﻿using KayakMes.Common.Dtos.WarehouseManageDto.Input;
using KayakMes.Common.Result;
using KayakMes.WarehouseManage.Application;
using KayakMes.WarehouseManage.Domain.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yitter.IdGenerator;

namespace KayakMes.WarehouseManage.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseController : ControllerBase
    {
        private readonly IWarehouseManageServices services;

        public WarehouseController(IWarehouseManageServices services)
        {
            this.services = services;
        }
        /// <summary>
        /// 添加仓库
        /// </summary>
        /// <param name="purchaseOrderModel">仓库模型</param>
        /// <returns>返回操作结果，成功返回1，失败返回0</returns>
        [HttpPost]
        public ApiResult<int> AddWarehouse(WarehouseAddDto warehouseModel)
        {
            return services.AddWarehouse(warehouseModel);
        }
        /// <summary>
        /// 更新仓库信息
        /// </summary>
        /// <param name="purchaseOrderModel">仓库模型</param>
        /// <returns>返回操作结果，成功返回1，失败返回0</returns>
        [HttpPut]
        public ApiResult<int> UpdateWarehouse(WarehouseModel warehouseModel)
        {
            return services.UpdateWarehouse(warehouseModel);
        }
        /// <summary>
        /// 逻辑删除仓库
        /// 将仓库的IsDeleted字段设置为true，而不是物理删除
        /// </summary>
        /// <param name="Id">仓库ID</param>
        /// <returns>返回操作结果，成功返回1，失败返回0</returns>
        [HttpPut]
        public ApiResult<int> LogicDelWarehouse(long Id)
        {
            return services.LogicDelWarehouse(Id);
        }
        /// <summary>
        /// 获取仓库列表（支持分页查询）
        /// </summary>
        /// <param name="dto">仓库列表查询条件DTO</param>
        /// <returns>返回分页的仓库列表</returns>
        [HttpGet]
        public ApiPaging<WarehouseModel> GetAllWarehouse([FromQuery]WarehouseDto dto)
        {
            return services.GetAllWarehouse(dto);
        }
        /// <summary>
        /// 根据ID查询指定的仓库
        /// </summary>
        /// <param name="id">采仓库ID</param>
        /// <returns>返回操作结果，包含指定的仓库信息</returns>
        [HttpGet]
        public ApiResult<WarehouseModel> GetWarehouse(long Id)
        {
            return services.GetWarehouse(Id);     
        }
        /// <summary>
        /// 随机生成仓库编号
        /// </summary>
        /// <returns>格式为 PC001 的字符串</returns>
        [HttpGet]
        public string GetWarehouseCode()
        {
           return services.GetWarehouseCode();
        }
    }
}
